package com.lk.ii.controller;

import java.util.List;

import com.lk.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lk.common.annotation.Log;
import com.lk.common.enums.BusinessType;
import com.lk.ii.domain.IiTag;
import com.lk.ii.service.IIiTagService;
import com.lk.common.core.controller.BaseController;
import com.lk.common.core.domain.AjaxResult;
import com.lk.common.utils.poi.ExcelUtil;
import com.lk.common.core.page.TableDataInfo;

/**
 * 标签Controller
 * 
 * @author lk
 * @date 2021-02-02
 */
@Controller
@RequestMapping("/ii/tag")
public class IiTagController extends BaseController
{
    private String prefix = "ii/tag";

    @Autowired
    private IIiTagService iiTagService;

    @RequiresPermissions("ii:tag:view")
    @GetMapping()
    public String tag()
    {
        return prefix + "/tag";
    }

    /**
     * 查询标签列表
     */
    @RequiresPermissions("ii:tag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IiTag iiTag)
    {
        startPage();
        List<IiTag> list = iiTagService.selectIiTagList(iiTag);
        return getDataTable(list);
    }

    /**
     * 导出标签列表
     */
    @RequiresPermissions("ii:tag:export")
    @Log(title = "标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IiTag iiTag)
    {
        List<IiTag> list = iiTagService.selectIiTagList(iiTag);
        ExcelUtil<IiTag> util = new ExcelUtil<IiTag>(IiTag.class);
        return util.exportExcel(list, "tag");
    }

    /**
     * 新增标签
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存标签
     */
    @RequiresPermissions("ii:tag:add")
    @Log(title = "标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IiTag iiTag)
    {
        iiTag.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(iiTagService.insertIiTag(iiTag));
    }

    /**
     * 修改标签
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IiTag iiTag = iiTagService.selectIiTagById(id);
        mmap.put("iiTag", iiTag);
        return prefix + "/edit";
    }

    /**
     * 修改保存标签
     */
    @RequiresPermissions("ii:tag:edit")
    @Log(title = "标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IiTag iiTag)
    {
        iiTag.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(iiTagService.updateIiTag(iiTag));
    }

    /**
     * 删除标签
     */
    @RequiresPermissions("ii:tag:remove")
    @Log(title = "标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iiTagService.deleteIiTagByIds(ids));
    }
}
